package close.mazegame.screens;

import com.badlogic.gdx.Gdx;

import close.mazegame.art.MiscArt;
import close.mazegame.input.uiinput.UIInput.UIKeys;
import close.mazegame.InputHandler;
import close.mazegame.MazeGame;

public class MenuScreen extends Screen {

	private int select = 0;
	private String[] menuItems = { "START GAME", "EXIT" };
	
	@Override
	public void render() {
		spriteBatch.begin();
		draw(MiscArt.bg, 0, 0, MazeGame.WIDTH, MazeGame.HEIGHT);
		draw(MiscArt.title, 0, 0, MazeGame.WIDTH, MazeGame.HEIGHT);

		String msg = "COPYRIGHT ME I GUESS";
		drawString(msg, 0, MazeGame.HEIGHT - 9, 1);

		for (int i = 0; i < menuItems.length; i++) {
			if (i == select) {
				drawString("- " + menuItems[i], MazeGame.WIDTH / 2 - (msg.length() * 8) - 200, MazeGame.HEIGHT / 2 - (i * 24), 2);
			} else {
				drawString(menuItems[i], MazeGame.WIDTH / 2 - (msg.length() * 8) - 200, MazeGame.HEIGHT / 2 - (i * 24), 2);
			}
		}

		spriteBatch.end();
	}

	@Override
	public void update(float delta) {
		if(InputHandler.uiInput.isTyped(UIKeys.UI_UP)){
			select--;
		}
		if(InputHandler.uiInput.isTyped(UIKeys.UI_DOWN)){
			select++;
		}
		while(select < 0){
			select += menuItems.length;
		}
		select = select%menuItems.length;
		
		if(InputHandler.uiInput.isTyped(UIKeys.UI_ENTER)){
			if(select == 0){
				setScreen(new GameScreen());
			} else if(select == 1){
				Gdx.app.exit();
			}
		}
		
		if(InputHandler.uiInput.isTyped(UIKeys.UI_ESCAPE)){
			Gdx.app.exit();
		}
	}

	@Override
	public boolean isOverlay() {
		return false;
	}

}
